package jjn.effective_java.chapter6.item34;

/**
 * @author Jiang Jining
 * @since 2023-04-26 22:57
 */
public enum OperationV1 {
    PLUS, MINUS, TIMES, DIVIDE;
    
    public double apply(double x, double y) {
        switch (this) {
            case PLUS -> {
                return x + y;
            }
            case MINUS -> {
                return x - y;
            }
            case TIMES -> {
                return x * y;
            }
            case DIVIDE -> {
                return x / y;
            }
        }
        // 没有本句会报错
        throw new AssertionError("Unknown operation: " + this);
    }
}
